* ====================================================================== * Stefanos Moschidis - SAP Certified Technical Consultant * ====================================================================== * ====================================================================== * Example of SAPSCRIPT * ====================================================================== REPORT Z_EXAMPLE_OF_SAPSCRIPT . * ====================================================================== * data declarations section * ====================================================================== tables : kna1 , t001 . data : begin of i_vbrk occurs 0 . include structure vbrk . data : end of i_vbrk . data : begin of i_vbrp occurs 0 . include structure vbrp . data : end of i_vbrp . data : msy_subrc like sy-subrc . * ====================================================================== * Selection Screen Default * ====================================================================== select-options : mfkdat for I_vbrk-fkdat . select-options : mvtweg for I_vbrk-vtweg . * ====================================================================== * Start of Selection * ====================================================================== start-of-selection . clear : i_vbrk , i_vbrk[] . select * from vbrk into corresponding fields of table i_vbrk where fkdat in mfkdat and vtweg in mvtweg . clear : i_vbrp , i_vbrp[] . select * from vbrp into corresponding fields of table i_vbrp for all entries in i_vbrk where vbeln = i_vbrk-vbeln . * ====================================================================== * End of Selection * ====================================================================== End-of-Selection . perform open_form using msy_subrc . check msy_subrc eq 0 . loop at i_vbrk . perform Start_form using msy_subrc . check msy_subrc eq 0 . clear : t001 . select single * from t001 where bukrs eq i_vbrk-bukrs . perform write_form using 'OUR_ADDR' SPACE 'SET' msy_subrc . check msy_subrc eq 0 . clear : kna1 . select single * from kna1 where kunnr eq i_vbrk-kunag . perform write_form using 'CUSTADDR' SPACE 'SET' msy_subrc . check msy_subrc eq 0 . perform write_form using 'HEADER' SPACE 'SET' msy_subrc . check msy_subrc eq 0 . perform write_form using 'MAIN' 'ITEM_HEADER' 'SET' msy_subrc . check msy_subrc eq 0 . loop at i_vbrp where vbeln = i_vbrk-vbeln . perform write_form using 'MAIN' 'ITEM_LINE' 'APPEND' msy_subrc . check msy_subrc eq 0 . endloop . perform end_form using msy_subrc . check msy_subrc eq 0 . endloop . perform close_form using msy_subrc . check msy_subrc eq 0 . *&---------------------------------------------------------------------* *& Form open_form *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM open_form using msy_subrc . CALL FUNCTION 'OPEN_FORM' EXPORTING * APPLICATION = 'TX' * ARCHIVE_INDEX = * ARCHIVE_PARAMS = * DEVICE = 'PRINTER' DIALOG = 'X' FORM = 'Z_EXAMPLE_BILLNG' LANGUAGE = SY-LANGU * OPTIONS = * MAIL_SENDER = * MAIL_RECIPIENT = * MAIL_APPL_OBJECT = * RAW_DATA_INTERFACE = '*' * IMPORTING * LANGUAGE = * NEW_ARCHIVE_PARAMS = * RESULT = EXCEPTIONS CANCELED = 1 DEVICE = 2 FORM = 3 OPTIONS = 4 UNCLOSED = 5 MAIL_OPTIONS = 6 ARCHIVE_ERROR = 7 INVALID_FAX_NUMBER = 8 MORE_PARAMS_NEEDED_IN_BATCH = 9 SPOOL_ERROR = 10 OTHERS = 11 . msy_subrc = SY-SUBRC . ENDFORM. " open_form *&---------------------------------------------------------------------* *& Form close_form *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM close_form using msy_subrc . CALL FUNCTION 'CLOSE_FORM' * IMPORTING * RESULT = * RDI_RESULT = * TABLES * OTFDATA = EXCEPTIONS UNOPENED = 1 BAD_PAGEFORMAT_FOR_PRINT = 2 SEND_ERROR = 3 SPOOL_ERROR = 4 OTHERS = 5 . msy_subrc = SY-SUBRC . ENDFORM. " close_form *&---------------------------------------------------------------------* *& Form Start_form *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_MSY_SUBRC text *----------------------------------------------------------------------* FORM Start_form USING MSY_SUBRC. CALL FUNCTION 'START_FORM' * EXPORTING * ARCHIVE_INDEX = * FORM = ' ' * LANGUAGE = ' ' * STARTPAGE = ' ' * PROGRAM = ' ' * MAIL_APPL_OBJECT = * IMPORTING * LANGUAGE = EXCEPTIONS FORM = 1 FORMAT = 2 UNENDED = 3 UNOPENED = 4 UNUSED = 5 SPOOL_ERROR = 6 OTHERS = 7 . msy_subrc = SY-SUBRC . ENDFORM. " Start_form *&---------------------------------------------------------------------* *& Form stop_form *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_MSY_SUBRC text *----------------------------------------------------------------------* FORM end_form USING P_MSY_SUBRC. CALL FUNCTION 'END_FORM' * IMPORTING * RESULT = EXCEPTIONS UNOPENED = 1 BAD_PAGEFORMAT_FOR_PRINT = 2 SPOOL_ERROR = 3 OTHERS = 4 . msy_subrc = SY-SUBRC . ENDFORM. " stop_form *&---------------------------------------------------------------------* *& Form write_form *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_MWINDOW text * -->P_MELEMENT text * -->P_MFUNCTION text * -->P_MSY_SUBRC text *----------------------------------------------------------------------* FORM write_form USING MWINDOW MELEMENT MFUNCTION MSY_SUBRC. CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = MELEMENT FUNCTION = MFUNCTION TYPE = 'BODY' WINDOW = MWINDOW * IMPORTING * PENDING_LINES = EXCEPTIONS ELEMENT = 1 FUNCTION = 2 TYPE = 3 UNOPENED = 4 UNSTARTED = 5 WINDOW = 6 BAD_PAGEFORMAT_FOR_PRINT = 7 SPOOL_ERROR = 8 OTHERS = 9 . msy_subrc = SY-SUBRC . ENDFORM. " write_form